#include "../include/Stack.h"
#include <iostream>
using namespace std;

void StructStack::Stack::Link::initialize(void* dat,Link* nxt){
    data =dat;
    next =nxt;
}

void StructStack::Stack::init(){
    head =0;
}

void StructStack::Stack::push(void* dat){
    Link* newLink = new Link;
    newLink->initialize(dat,head);
    head = newLink;
}

void* StructStack::Stack::peek(){
    return head->data;
} 

void* StructStack::Stack::pop(){
    if(head ==0){
      return 0;
    }
    void* result = head ->data;
    Link* oldHead =head;
    head = head ->next;
    delete oldHead;
    return result;
}

void StructStack::Stack::cleanup(){
    while(head!=0&& head->next!=nullptr){
       pop();
    }
    cout<< "cleanup over"<<endl;
}